package com.weipu.common.constants;

import android.util.Log;

import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import java.util.Properties;

/**
 * Created by wWX173427 on 2017/5/9.
 */

public class DxConfig {

    private static Properties PROPERTIES;

    //https校验
    public static boolean HTTPS_VERIFY;

    //地址配置
    public static String BASE_HOME_URL;
    public static String BASE_URL;
    public static String SHIPPINGADRESS_URL_M;
    public static String SHIPPINGADRESS_URL;
    public static String FAQ_URL;
    public static String GET_IP;
    public static String GET_IP_COUNTRY_INTERFACESUFFIX;


    //开发接口鉴权账号
    public static String PARAMETER_DEV_AUTHENTICATE_PASSWORD;
    public static String PARAMETER_DEV_AUTHENTICATE_ACCOUNT;

    public static void init(InputStream is) {
        PROPERTIES = new Properties();
        try {
            PROPERTIES.load(is);
            HTTPS_VERIFY = getPropertyBoolean("HTTPS_VERIFY");
            BASE_HOME_URL = getProperty("BASE_HOME_URL");
            BASE_URL = getProperty("BASE_URL");
            SHIPPINGADRESS_URL_M = getProperty("SHIPPINGADRESS_URL_M");
            SHIPPINGADRESS_URL = getProperty("SHIPPINGADRESS_URL");
            FAQ_URL = getProperty("FAQ_URL");
            GET_IP = getProperty("GET_IP");
            GET_IP_COUNTRY_INTERFACESUFFIX = getProperty("GET_IP_COUNTRY_INTERFACESUFFIX");
            PARAMETER_DEV_AUTHENTICATE_PASSWORD = getProperty("PARAMETER_DEV_AUTHENTICATE_PASSWORD");
            PARAMETER_DEV_AUTHENTICATE_ACCOUNT = getProperty("PARAMETER_DEV_AUTHENTICATE_ACCOUNT");
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException var2) {
                throw new RuntimeException(var2);
            }
        }
    }

    private static String getProperty(String name) {
        String key = name.toLowerCase(Locale.getDefault());
        return PROPERTIES.getProperty(key);
    }

    private static boolean getPropertyBoolean(String name) {
        String value = getProperty(name);
        return Boolean.parseBoolean(value);
    }

}
